package string;

public class StringBuilderDemo1 {
    public static void main(String[] args) {
        //定义一个字符串"你好"
        StringBuilder str=new StringBuilder("你好");
        //在"你好"后面添加内容,将字符串变成"你好,hello"
        StringBuilder str2=str.append(",ihello!");//str2与str1指向同一个堆空间
        System.out.println(str2);
        System.out.println(str);
        //将字符串变成"你好,iHELLO!"
        //两种方法:
        //1.使用delete方法删除hello,然后插入HELLO
        System.out.println("替换后:"+str.delete(4,9).insert(4,"HELLO"));
        //2.使用replace方法替换
        System.out.println("替换后2:"+str.replace(4,9,"HELLO"));
        //在字符串"你好,iHELLO!"中取出"你好"并输出
        System.out.println(str.substring(0,2));
    }
}
